package com.ys.controller.web.sys;

import com.ys.config.MenuId;
import com.ys.entity.sys.TsUserBankInfo;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
@RequestMapping("/web/sys/tsUserBankInfo")
public class WebTsUserBankInfoController {
	

	@Autowired
	private CommonApiService<TsUserBankInfo> commonApiService;


	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response,@RequestParam Map<String, Object> params){
		try {
			return commonApiService.toAdd(model, new TsUserBankInfo().setStatus(1), MenuId.TS_UserBankInfo, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, "数据有误，请联系客服");
		}
	}



	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,@RequestParam Map<String, Object> params){
		if (params.get("id") == null){
			return W.error(model, "id不能为空");
		}

		Long id = Long.valueOf((params.get("id").toString()));

		Map<String, Object> entity = new TsUserBankInfo().setId(id)
				.addLeftJoin("TS_UserInfo B on  B.UserId = A.UserId")
				.addField("B.deptName,B.roleName,(B.UserId + '/' + B.UserName) AS _ys_nameLinked")
				.queryFirstMap();
		if (entity == null){
			return W.error(model, "员工银行账户不存在!");
		}

		try {
			return commonApiService.toEdit(model, id, new TsUserBankInfo().setId(id), MenuId.TS_UserBankInfo, entity, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, "数据有误，请联系客服");
		}
	}

}
